<template>
  <div class="out">
    <div class="tit">
      <span @click="outRoute">
        <i class="el-icon-arrow-left"></i>
      </span>
      <p>{{title}}</p>
      <i></i>
    </div>
    <div class="detailDom">
      <img :src="detailobj.src" alt />
      <p>{{detailobj.title}}</p>
      <p>￥{{parseInt(detailobj.price)}}</p>
      <el-button type="primary" @click="detailaddCount(detailobj)">加入购物车</el-button>
    </div>
  </div>
</template>

<style lang="less" scoped>
.out {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.out .tit {
  height: 0.5rem;
  background: #1d91a0;
  font-size: 0.12rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  i {
    font-size: 0.3rem;
  }
}
.detailDom {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}
</style>

<script>
import { mapState, mapActions } from "vuex";
export default {
  data: function() {
    return {
      title: "",
      detailobj: ""
    };
  },
  computed: {
    ...mapState("homeStore", ["iphoneList"])
  },
  created() {
    this.title = this.$route.params.id;
    this.detailobj = this.iphoneList.filter(item => {
      return item.title == this.title;
    })[0];
    console.log(this.detailobj);
  },
  methods: {
    ...mapActions("cartStore", ["set_change_cartList"]),
    outRoute() {
      window.history.go(-1);
    },
    detailaddCount(obj) {
      this.set_change_cartList(obj);
      this.$message({
        type: "success",
        message: "加入购物车成功",
        duration: 500
      });
    }
  }
};
</script>